﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using System.Drawing;
using DevComponents.DotNetBar;
namespace DataAccess
{
    public class XuLyDataGridView
    {
        public static DataGridViewComboBoxColumn CotCombo(string TenCot, object Datasource, string display, string value)
        {
            DataGridViewComboBoxColumn cl = CotCombo(TenCot, Datasource);

            try
            {
                cl.DisplayMember = display;
                cl.ValueMember = value;
            }
            catch (Exception)
            {
            }
            return cl;
        }
        public static DataGridViewComboBoxColumn CotCombo(string TenCot, object Datasource, string display, string value, string propertyname)
        {
            DataGridViewComboBoxColumn cl = CotCombo(TenCot, Datasource, display, value);
            cl.DataPropertyName = propertyname;
            return cl;
        }
        public static DataGridViewComboBoxColumn CotCombo(string TenCot, object Datasource)
        {
            DataGridViewComboBoxColumn cl = new DataGridViewComboBoxColumn();
            cl.HeaderText = TenCot;
            cl.DataSource = Datasource;
            return cl;
        }
        public static DataGridViewButtonColumn CotButton(string TenCot)
        {
            DataGridViewButtonXColumn cot = new DataGridViewButtonXColumn();
            cot.HeaderText = cot.Text = TenCot;
            cot.UseColumnTextForButtonValue = true;
            cot.ToolTipText = "Nhấn để " + TenCot + " hàng này";
            return cot;
        }
        public static DataGridViewButtonColumn CotButton(string TenCot, int width)
        {
            DataGridViewButtonXColumn cot = new DataGridViewButtonXColumn();
            cot.HeaderText = cot.Text = TenCot;
            cot.UseColumnTextForButtonValue = true;
            cot.Width = width;
            cot.ToolTipText = "Nhấn để " + TenCot + " hàng này";
            return cot;
        }
        public static bool AddCotButtom(DataGridView dgr, string Text)
        {
            try
            {
                dgr.Columns.Add(CotButton(Text));
                return true;
            }
            catch (Exception)
            {
            }
            return false;
        }
        public static bool AddCotButtom(DataGridView dgr, string Text, int width)
        {
            try
            {
                dgr.Columns.Insert(0, CotButton(Text, 10));
                return true;
            }
            catch (Exception)
            {
            }
            return false;
        }



        public static void dgrMouseMove(DataGridView dgr)
        {
            dgr.CellMouseMove += new DataGridViewCellMouseEventHandler(dgr_CellMouseMove);
            dgr.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }

        static void dgr_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                DataGridView d = sender as DataGridView;
                d.CurrentCell = d.Rows[e.RowIndex].Cells[e.ColumnIndex];
            }
            catch (Exception)
            {
            }
        }

        public static void Style(DataGridViewX dgr)
        {
            dgr.AllowUserToAddRows = false;
            dgr.AllowUserToDeleteRows = false;
            dgr.AllowUserToResizeColumns = false;
            dgr.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            dgr.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
            dgr.ColumnHeadersHeight = 40;
            dgr.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dgr.ReadOnly = true;
            dgr.RowHeadersVisible = false;
            dgr.RowHeadersWidth = 50;
            dgr.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            dgr.RowTemplate.Height = 40;
            dgr.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            dgr.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
            dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(207)))), ((int)(((byte)(221)))), ((int)(((byte)(238)))));
            dataGridViewCellStyle1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            dataGridViewCellStyle1.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Blue;
            dgr.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
            DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(207)))), ((int)(((byte)(221)))), ((int)(((byte)(238)))));
            dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(163)));
            dataGridViewCellStyle2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.Blue;
            dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            dgr.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
            DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window;
            dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(163)));
            dataGridViewCellStyle3.ForeColor = System.Drawing.Color.Black;
            dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle3.SelectionForeColor = System.Drawing.Color.Blue;
            dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
            dgr.DefaultCellStyle = dataGridViewCellStyle3;
            dgr.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(170)))), ((int)(((byte)(170)))), ((int)(((byte)(170)))));
            DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
            dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(163)));
            dataGridViewCellStyle4.ForeColor = System.Drawing.Color.Blue;
            dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
            dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            dgr.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
            DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
            dataGridViewCellStyle5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            dataGridViewCellStyle5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
            dataGridViewCellStyle5.SelectionForeColor = System.Drawing.Color.Blue;
            dgr.RowsDefaultCellStyle = dataGridViewCellStyle5;
            dgr.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
        }
        public static void Style(DataGridViewX[] listdgr)
        {
            foreach (DataGridViewX dgr in listdgr)
                Style(dgr);
        }
        public static void Style2(DataGridViewX dgr)
        {
            dgr.AllowUserToAddRows = false;
            dgr.AllowUserToDeleteRows = false;
            dgr.AllowUserToResizeColumns = false;
            dgr.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            dgr.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
            dgr.ColumnHeadersHeight = 40;
            dgr.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dgr.ReadOnly = true;
            dgr.RowHeadersVisible = false;
            dgr.RowHeadersWidth = 50;
            dgr.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            dgr.RowTemplate.Height = 40;
            dgr.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            dgr.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
        }
        public static void Style2(DataGridViewX dgr, int height)
        {
            dgr.AllowUserToAddRows = false;
            dgr.AllowUserToDeleteRows = false;
            dgr.AllowUserToResizeColumns = false;
            dgr.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            dgr.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
            dgr.ColumnHeadersHeight = 40;
            dgr.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dgr.ReadOnly = true;
            dgr.RowHeadersVisible = false;
            dgr.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            dgr.RowTemplate.Height = height;
            dgr.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            dgr.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;

        }
    }
}
